package 数据结构设计高频题;

import java.io.*;
import java.util.HashMap;

/**
 * @author 冷加宝
 * @version 1.0
 */
// setAll功能的哈希表
// 测试链接 : https://www.nowcoder.com/practice/7c4559f138e74ceb9ba57d76fd169967
// 请同学们务必参考如下代码中关于输入、输出的处理
// 这是输入输出处理效率很高的写法
// 提交以下的code，提交时请把类名改成"Main"，可以直接通过
public class Code01_SetAllHashMap {

    public static HashMap<Integer, int []> map = new HashMap<>();
    public static int setAllValue;
    public static int setAllTime;
    public static int cnt;

    public static void put(int k, int v){
        if(map.containsKey(k)){
            int[] value = map.get(k);
            value[0] = v;
            value[1] = cnt++;
        }else{
            int[] value = new int[2];
            value[0] = v;
            value[1] = cnt++;
            map.put(k, value);
        }
    }

    public static void setAllValue(int v){
        setAllValue = v;
        setAllTime = cnt++;
    }


    public static int get(int k){
        if(!map.containsKey(k)){
            return -1;
        }
        int[] value = map.get(k);
        if(value[1] <= setAllTime){
            return setAllValue;
        }else {
            return value[0];
        }
    }

    public static int n, op, a, b;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while(in.nextToken() != StreamTokenizer.TT_EOF){
            map.clear();
            setAllTime = -1;
            setAllValue = 0;
            cnt = 0;
            n = (int) in.nval;
            for(int i = 0; i < n; i++){
                in.nextToken();
                op = (int) in.nval;
                if(op == 1){
                    in.nextToken();
                    a = (int) in.nval;
                    in.nextToken();
                    b = (int) in.nval;
                    put(a, b);
                }else if(op == 2){
                    in.nextToken();
                    a = (int) in.nval;
                    System.out.println(get(a));
                }else{
                    in.nextToken();
                    b = (int) in.nval;
                    setAllValue(b);
                }
            }
        }
        out.flush();
        out.close();
        br.close();
    }
}
